package com.bjpowernode.dao.impl;

import com.bjpowernode.dao.StudentDao;
import com.bjpowernode.entity.Student;
import com.bjpowernode.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author shentianyu
 * @date 2020-07-06 19:39
 */
public class StudentDaoImpl implements StudentDao {

    @Override
    public List<Student> selectStudents() {
        //1、获取sqlSession对象
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        String sqlId = "com.bjpowernode.dao.StudentDao.selectStudents";
        List<Student> students = sqlSession.selectList(sqlId);
        return students;
    }

    @Override
    public int insertStudent(Student student) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        String sqlId = "com.bjpowernode.dao.StudentDao.insertStudent";
        int res = sqlSession.insert(sqlId,student);
        sqlSession.commit();
        sqlSession.close();
        return res;
    }
}
